{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'pandas'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mModuleNotFoundError\u001b[0m              Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-1-f541cd1da0f1>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mpandas\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mpd\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mpdfminer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpdfinterp\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mPDFResourceManager\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mPDFPageInterpreter\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mpdfminer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconverter\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mTextConverter\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      4\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mpdfminer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlayout\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mLAParams\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mpdfminer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpdfpage\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mPDFPage\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'pandas'"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter\n",
    "from pdfminer.converter import TextConverter\n",
    "from pdfminer.layout import LAParams\n",
    "from pdfminer.pdfpage import PDFPage\n",
    "from io import StringIO\n",
    "from requests import get\n",
    "from tika import parser\n",
    "import urllib.request"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "def download_save_img(url, file_name):\n",
    "    urllib.request.urlretrieve(url, file_name)\n",
    "\n",
    "def download_pdf(url, file_name):\n",
    "    with open(file_name, \"wb\") as file:\n",
    "        response = get(url)\n",
    "        file.write(response.content)\n",
    "        \n",
    "def read_and_write(file_name, text_name):\n",
    "    with open(text_name, \"w\", encoding='utf8') as writer:\n",
    "        parsed = parser.from_file(file_name)\n",
    "        text = parsed['content']\n",
    "        lines = text.split('\\n')\n",
    "        full_text = []\n",
    "        for line in lines:\n",
    "            if line == '':\n",
    "                continue\n",
    "            else:\n",
    "                writer.write(line.replace('�', ' ')+'\\n')\n",
    "                \n",
    "def read_and_return(file_name):\n",
    "    parsed = parser.from_file(file_name)\n",
    "    text = parsed['content']\n",
    "    lines = text.split('\\n')\n",
    "    full_text = \"\"\n",
    "    for line in lines:\n",
    "        if line == '':\n",
    "            continue\n",
    "        else:\n",
    "            full_text+=(line.replace('�', ' ')+'\\n')\n",
    "    return full_text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_detail = pd.read_excel('csv/pill_details.xls')\n",
    "data_detail = data_detail[['품목일련번호', '허가일자', '원료성분', '마약류분류', '완제원료구분', '포장단위', '보험코드', '전문일반', '총량', '취소상태',\n",
    "       '변경내용', '등록자id', '첨부문서', '제심사기간', '효능효과', '저장방법', '신약여부', '유효기간',\n",
    "       '용법용량', '첨가제명', '성상', '재심사대상', '허가및신고구분',\n",
    "       '취소일자', '표준코드', '주의사항', '주성분명']]\n",
    "\n",
    "data_list = pd.read_csv('csv/pill_list.csv')\n",
    "data_list = data_list[['품목일련번호', '품목명', '업소일련번호', '업소명', '큰제품이미지', '표시앞', '표시뒤', '의약품제형',\n",
    "       '색상앞', '색상뒤', '분할선앞', '분할선뒤', '크기장축', '크기단축', '크기두께', '이미지생성일자(약학정보원)',\n",
    "       '분류번호', '분류명', '전문일반구분', '품목허가일자', '제형코드명', '표기내용앞', '표기내용뒤', '표기이미지앞',\n",
    "       '표기이미지뒤', '표기코드앞', '표기코드뒤', '변경일자']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_Data = pd.merge(data_list, data_detail, on='품목일련번호')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "img = '큰제품이미지'\n",
    "eff = '효능효과'\n",
    "use = '용법용량'\n",
    "war = '주의사항'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total row number: 21657\n",
      "389 Pill ID: 200409973--------------------\n"
     ]
    },
    {
     "ename": "ValueError",
     "evalue": "unknown url type: '-'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-5-d995bdbbf9fd>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m     12\u001b[0m     \u001b[0;31m## 큰제품이미지\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     13\u001b[0m     \u001b[0mfile_name\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpill_id\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;34m'_img'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 14\u001b[0;31m     \u001b[0mdownload_save_img\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpill_img\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'img/'\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mfile_name\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;34m'.jpg'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     15\u001b[0m     \u001b[0mnew_Data\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0miloc\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0midx\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfile_name\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;34m'.jpg'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     16\u001b[0m     \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"image Done.\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m<ipython-input-1-5d42223a7327>\u001b[0m in \u001b[0;36mdownload_save_img\u001b[0;34m(url, file_name)\u001b[0m\n\u001b[1;32m     10\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     11\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mdownload_save_img\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0murl\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfile_name\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 12\u001b[0;31m     \u001b[0murllib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrequest\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0murlretrieve\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0murl\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfile_name\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     13\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     14\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mdownload_pdf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0murl\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfile_name\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/envs/csv/lib/python3.8/urllib/request.py\u001b[0m in \u001b[0;36murlretrieve\u001b[0;34m(url, filename, reporthook, data)\u001b[0m\n\u001b[1;32m    245\u001b[0m     \u001b[0murl_type\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpath\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_splittype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0murl\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    246\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 247\u001b[0;31m     \u001b[0;32mwith\u001b[0m \u001b[0mcontextlib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclosing\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0murlopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0murl\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mfp\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    248\u001b[0m         \u001b[0mheaders\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minfo\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    249\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/envs/csv/lib/python3.8/urllib/request.py\u001b[0m in \u001b[0;36murlopen\u001b[0;34m(url, data, timeout, cafile, capath, cadefault, context)\u001b[0m\n\u001b[1;32m    220\u001b[0m     \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    221\u001b[0m         \u001b[0mopener\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_opener\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 222\u001b[0;31m     \u001b[0;32mreturn\u001b[0m \u001b[0mopener\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0murl\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    223\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    224\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0minstall_opener\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mopener\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/envs/csv/lib/python3.8/urllib/request.py\u001b[0m in \u001b[0;36mopen\u001b[0;34m(self, fullurl, data, timeout)\u001b[0m\n\u001b[1;32m    507\u001b[0m         \u001b[0;31m# accept a URL or a Request object\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    508\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfullurl\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 509\u001b[0;31m             \u001b[0mreq\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mRequest\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfullurl\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    510\u001b[0m         \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    511\u001b[0m             \u001b[0mreq\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfullurl\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/envs/csv/lib/python3.8/urllib/request.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, url, data, headers, origin_req_host, unverifiable, method)\u001b[0m\n\u001b[1;32m    326\u001b[0m                  \u001b[0morigin_req_host\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0munverifiable\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    327\u001b[0m                  method=None):\n\u001b[0;32m--> 328\u001b[0;31m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfull_url\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0murl\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    329\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mheaders\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    330\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0munredirected_hdrs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/envs/csv/lib/python3.8/urllib/request.py\u001b[0m in \u001b[0;36mfull_url\u001b[0;34m(self, url)\u001b[0m\n\u001b[1;32m    352\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_full_url\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0munwrap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0murl\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    353\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_full_url\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfragment\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_splittag\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_full_url\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 354\u001b[0;31m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_parse\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    355\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    356\u001b[0m     \u001b[0;34m@\u001b[0m\u001b[0mfull_url\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdeleter\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/envs/csv/lib/python3.8/urllib/request.py\u001b[0m in \u001b[0;36m_parse\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    381\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtype\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrest\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_splittype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_full_url\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    382\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtype\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 383\u001b[0;31m             \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"unknown url type: %r\"\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfull_url\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    384\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhost\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mselector\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_splithost\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrest\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    385\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhost\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mValueError\u001b[0m: unknown url type: '-'"
     ]
    }
   ],
   "source": [
    "row_num = len(new_Data.index)\n",
    "print(\"total row number:\",row_num)\n",
    "\n",
    "for idx in range(389, row_num):\n",
    "    pill_id = new_Data.loc[idx]['품목일련번호']\n",
    "    print(idx,\"Pill ID: \"+str(pill_id)+\"-\"*20)\n",
    "    pill_img = new_Data.loc[idx][img]\n",
    "    pill_eff = new_Data.loc[idx][eff]\n",
    "    pill_use = new_Data.loc[idx][use]\n",
    "    pill_war = new_Data.loc[idx][war]\n",
    "    \n",
    "    ## 큰제품이미지\n",
    "    file_name = str(pill_id)+'_img'\n",
    "    download_save_img(pill_img, 'img/'+file_name+'.jpg')\n",
    "    new_Data.iloc[idx,4] = file_name+'.jpg'\n",
    "    print(\"image Done.\")\n",
    "    \n",
    "    ## 효능효과\n",
    "    file_name = str(pill_id)+'_effect'\n",
    "    download_pdf(pill_eff, 'pdf/'+file_name+'.pdf')\n",
    "    text = read_and_return('pdf/'+file_name+'.pdf')\n",
    "    new_Data.iloc[idx,41] = text\n",
    "    print(new_Data.loc[idx][eff])\n",
    "    print(\"effect Done.\")\n",
    "    \n",
    "    ## 용법용량\n",
    "    file_name = str(pill_id)+'_usage'\n",
    "    download_pdf(pill_use, 'pdf/'+file_name+'.pdf')\n",
    "    text = read_and_return('pdf/'+file_name+'.pdf')\n",
    "    new_Data.iloc[idx,45] = text\n",
    "    print(new_Data.loc[idx][use])\n",
    "    print(\"usage Done.\")\n",
    "    \n",
    "    ## 주의사항\n",
    "    file_name = str(pill_id)+'_warning'\n",
    "    download_pdf(pill_war, 'pdf/'+file_name+'.pdf')\n",
    "    text = read_and_return('pdf/'+file_name+'.pdf')\n",
    "    new_Data.iloc[idx,52] = text\n",
    "    print(new_Data.loc[idx][war])\n",
    "    print(\"warning Done.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<bound method NDFrame.head of           품목일련번호                           품목명    업소일련번호         업소명  \\\n",
       "0      199304470  징카민정40mg(은행엽건조엑스)(수출명:징카프란정)  19620008     영진약품(주)   \n",
       "1      197400571               아스코푸정(히벤즈산티페피딘)  19620008     영진약품(주)   \n",
       "2      200703756       저니스타서방정8밀리그램(히드로모르폰염산염)  19940315     (주)한국얀센   \n",
       "3      199703153                 씨즈날정(세티리진염산염)  19910005      (주)녹십자   \n",
       "4      200004062                         라니타드정  19910005      (주)녹십자   \n",
       "...          ...                           ...       ...         ...   \n",
       "21652  202002734         바이넥스탐스로신염산염서방정0.4밀리그램  19570004     (주)바이넥스   \n",
       "21653  202002148                  뉴빅사정(메만틴염산염)  19560008   (주)메디카코리아   \n",
       "21654  202001353               레로진정(레보세티리진염산염)  19960030   (주)넥스팜코리아   \n",
       "21655  202002152      리멘시아연질캡슐120밀리그램(은행엽건조엑스)  19560011     삼진제약(주)   \n",
       "21656  202003800                        케이셋세미정  20191087  주식회사케이에스제약   \n",
       "\n",
       "                                                  큰제품이미지         표시앞  표시뒤  \\\n",
       "0                                      199304470_img.jpg           -  Z40   \n",
       "1                                      197400571_img.jpg  ASCOUGHYJP    -   \n",
       "2                                      200703756_img.jpg         HM8    -   \n",
       "3                                      199703153_img.jpg         CZT  분할선   \n",
       "4                                      200004062_img.jpg         RNT    -   \n",
       "...                                                  ...         ...  ...   \n",
       "21652  https://nedrug.mfds.go.kr/pbp/cmn/itemImageDow...       BITS4    -   \n",
       "21653  https://nedrug.mfds.go.kr/pbp/cmn/itemImageDow...     MH분할선10  분할선   \n",
       "21654  https://nedrug.mfds.go.kr/pbp/cmn/itemImageDow...          NK    Z   \n",
       "21655  https://nedrug.mfds.go.kr/pbp/cmn/itemImageDow...         SJG    -   \n",
       "21656  https://nedrug.mfds.go.kr/pbp/cmn/itemImageDow...          마크    5   \n",
       "\n",
       "      의약품제형 색상앞 색상뒤  ...          유효기간  \\\n",
       "0        원형  연두   -  ...  제조일로부터 36 개월   \n",
       "1        원형  노랑   -  ...  제조일로부터 60 개월   \n",
       "2        원형  분홍   -  ...  제조일로부터 24 개월   \n",
       "3       장방형  하양   -  ...  제조일로부터 36 개월   \n",
       "4        원형  하양   -  ...  제조일로부터 36 개월   \n",
       "...     ...  ..  ..  ...           ...   \n",
       "21652    원형  하양   -  ...  제조일로부터 12 개월   \n",
       "21653    기타  하양   -  ...  제조일로부터 36 개월   \n",
       "21654   타원형  하양   -  ...  제조일로부터 24 개월   \n",
       "21655   타원형  갈색   -  ...  제조일로부터 24 개월   \n",
       "21656   장방형  주황   -  ...  제조일로부터 36 개월   \n",
       "\n",
       "                                                    용법용량  \\\n",
       "0      용법용량\\n성인\\n1) 말초동맥순환장애, 어지러움, 이명(귀울림): 은행엽건조엑스로...   \n",
       "1      용법용량\\n성인 : 히벤즈산티페피딘으로서 1일 66.42-132.84mg을 3회 분...   \n",
       "2      용법용량\\n다른 마약성 진통제와 같이, 통증의 치료를 위한 이 약의 안전하고 효과적...   \n",
       "3      용법용량\\n1. 성인 및 6세 이상의 소아 : 세티리진염산염으로서 1일 1회 10m...   \n",
       "4      용법용량\\n성인(15세이상,80세미만) : 1회 2정씩 복용하되 복용 후 5시간 이...   \n",
       "...                                                  ...   \n",
       "21652  https://nedrug.mfds.go.kr/pbp/cmn/pdfDownload/...   \n",
       "21653  https://nedrug.mfds.go.kr/pbp/cmn/pdfDownload/...   \n",
       "21654  https://nedrug.mfds.go.kr/pbp/cmn/pdfDownload/...   \n",
       "21655  https://nedrug.mfds.go.kr/pbp/cmn/pdfDownload/...   \n",
       "21656  https://nedrug.mfds.go.kr/pbp/cmn/pdfDownload/...   \n",
       "\n",
       "                                                    첨가제명  \\\n",
       "0      [M223369]인산수소칼슘수화물|[M254581]유당수화물|[M071119]전분글...   \n",
       "1      [M227968]유당수화물|[M245089]황색5호|[M040450]옥수수전분|[M...   \n",
       "2      [M209567]포비돈K29-32|[M202929]다이부틸하이드록시톨루엔|[M101...   \n",
       "3      [M081161]크로스포비돈|[M060073]미결정셀룰로오스|[M040450]옥수수...   \n",
       "4      [M081161]크로스포비돈|[M060073]미결정셀룰로오스|[M224556]오파드...   \n",
       "...                                                  ...   \n",
       "21652  [M254581]유당수화물|[M250072]히프로멜로오스2208|[M244405]카...   \n",
       "21653  [M224776]오파드라이흰색(85F18378)|[M081161]크로스포비돈|[M2...   \n",
       "21654  [M254581]유당수화물|[M243429]카르복시메틸셀룰로오스칼슘|[M211346...   \n",
       "21655  [M099858]콩기름|[M040791]황납|[M111459]소르비톨 액(비결정성)...   \n",
       "21656  [M211984]오파드라이흰색(03B28796)|[M080615]분말셀룰로오스|[M...   \n",
       "\n",
       "                                            성상 재심사대상  허가및신고구분        취소일자  \\\n",
       "0      (수출용) 하트형의 연녹색 제피정\\n(내수용) 연녹색의 원형필름 제피정   NaN       신고         NaN   \n",
       "1                                     황색의 정제임.   NaN       신고  20200101.0   \n",
       "2                         빨간색의 원형, 양면이 볼록한 서방정   NaN       허가         NaN   \n",
       "3                                흰색의 타원형 필름코팅정   NaN       신고         NaN   \n",
       "4                                 백색의 원형 필름코팅정   NaN       신고  20200701.0   \n",
       "...                                        ...   ...      ...         ...   \n",
       "21652                         흰색의 원형 서방성 필름코팅정   NaN       허가         NaN   \n",
       "21653                           흰색의 장방형 필름코팅정제   NaN       허가         NaN   \n",
       "21654                     흰색 또는 미황색의 타원형 필름코팅정   NaN       신고         NaN   \n",
       "21655            갈색의 유상 내용물을 함유한 암갈색의 타원형 연질캡슐   NaN       신고         NaN   \n",
       "21656                       연한 황색의 장방형 필름코팅 정제   NaN       허가         NaN   \n",
       "\n",
       "               표준코드                                               주의사항  \\\n",
       "0      8.806424e+12  사용상의주의사항\\n1. 다음과 같은 사람은 이 약을 복용(사용)하지 말 것\\n1) ...   \n",
       "1      8.806424e+12  사용상의주의사항\\n1. 부작용\\n1) 정신신경계 : 때때로 졸음, 불면, 어지러움,...   \n",
       "2      8.806469e+12  사용상의주의사항\\n1. 경고\\n마약류와 벤조디아제핀계 약물 또는 알코올을 포함하는 ...   \n",
       "3      8.806436e+12  사용상의주의사항\\n1. 다음과 같은 사람은 이 약을 복용(사용)하지 말 것\\n1) ...   \n",
       "4      8.806436e+12  사용상의주의사항\\n1. 다음 환자에는 투여하지 마십시오.\\n1) 다음 질환으로 치료...   \n",
       "...             ...                                                ...   \n",
       "21652  8.806431e+12  https://nedrug.mfds.go.kr/pbp/cmn/pdfDownload/...   \n",
       "21653  8.806460e+12  https://nedrug.mfds.go.kr/pbp/cmn/pdfDownload/...   \n",
       "21654  8.806625e+12  https://nedrug.mfds.go.kr/pbp/cmn/pdfDownload/...   \n",
       "21655  8.806478e+12  https://nedrug.mfds.go.kr/pbp/cmn/pdfDownload/...   \n",
       "21656  8.800590e+12  https://nedrug.mfds.go.kr/pbp/cmn/pdfDownload/...   \n",
       "\n",
       "                                                    주성분명  \n",
       "0                                       [M088948]은행엽건조엑스  \n",
       "1                                      [M051663]히벤즈산티페피딘  \n",
       "2                                     [M247991]히드로모르폰염산염  \n",
       "3                                       [M222857]세티리진염산염  \n",
       "4      [M222983]라니티딘염산염|[M040262]산화마그네슘|[M088538]수산화알...  \n",
       "...                                                  ...  \n",
       "21652                                   [M243979]탐스로신염산염  \n",
       "21653                                    [M242614]메만틴염산염  \n",
       "21654                                 [M244596]레보세티리진염산염  \n",
       "21655                                   [M088948]은행엽건조엑스  \n",
       "21656                  [M040353]아세트아미노펜|[M222893]트라마돌염산염  \n",
       "\n",
       "[21657 rows x 54 columns]>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_Data.head"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<bound method _OpenpyxlWriter.save of <pandas.io.excel._openpyxl._OpenpyxlWriter object at 0x7f8dccc819a0>>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "writer = pd.ExcelWriter(\"csv/pill_information.xlsx\")\n",
    "new_Data.to_excel(writer)\n",
    "writer.save"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
